package com.beesphere.products.throttling.processor.async;

import com.beesphere.products.throttling.AsyncCallback;
import com.beesphere.products.throttling.UnitOfWork;
import com.beesphere.products.throttling.processor.Processor;

/**
 * A more complex version of {@link Processor} which supports asynchronous
 * processing of the {@link Exchange}.  Any processor can be coerced to
 * have an {@link AsyncProcessor} interface
 */
public interface AsyncProcessor extends Processor {

    /**
     * Processes the message exchange.  Similar to {@link Processor#process}, but
     * the caller supports having the message asynchronously processed.
     *
     * @param unitOfWork the {@link UnitOfWork} to process
     * @param  callback the {@link AsyncCallback} will be invoked when the processing
     *         of the exchange is completed. If the exchange is completed synchronously, then the 
     *         callback is also invoked synchronously.  The callback should therefore be careful of
     *         starting recursive loop.
     *         
     * @return true if the processing was completed synchronously.
     */
    boolean process (UnitOfWork unitOfWork, long timeout, AsyncCallback callback);
    
}
